/* $Revision: $ $Date: $
 * 
 * Copyright (C) 2009 Robert Stephan
 * 
 * This file is part of *** CaCaO - Card Catalogs Online ***
 *
 * CaCaO is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * CaCao is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package cacao.client.ui;

import java.util.HashMap;
import java.util.Map;

import cacao.client.CaCaO;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PushButton;

public class BottomMenuCmp extends Composite implements CaCaOComposite, ClickHandler{
	private CaCaO application;
	private ImageCmp imageCmp;
	private PushButton btnZoom100, btnZoomHeight, btnZoomIn, btnZoomOut, btnZoomPage, btnZoomWidth; 
	private Map<PushButton, Integer> zoomModes;
	private DockPanel panel;
	
	public BottomMenuCmp(CaCaO app){
		application=app;
		zoomModes = new HashMap<PushButton, Integer>();
	
		panel = new DockPanel();
		panel.setStylePrimaryName("dp-imageZoom");

		btnZoom100 = createZoomButton(panel, application.getIconImageBundle().zoom100Icon(), ImageCmp.ZOOM_100, application.getMessages().zoom100());
		btnZoomHeight = createZoomButton(panel, application.getIconImageBundle().zoomHeightIcon(), ImageCmp.ZOOM_HEIGHT, application.getMessages().zoomHeight());
		btnZoomWidth = createZoomButton(panel, application.getIconImageBundle().zoomWidthIcon(), ImageCmp.ZOOM_WIDTH, application.getMessages().zoomWidth());
		//btnZoomPage = createZoomButton(panel, application.getIconImageBundle().zoomPageIcon(), ImageCmp.ZOOM_PAGE, application.getMessages().zoomPage);
		btnZoomIn = createZoomButton(panel, application.getIconImageBundle().zoomInIcon(), ImageCmp.ZOOM_IN, application.getMessages().zoomIn());
		btnZoomOut = createZoomButton(panel, application.getIconImageBundle().zoomOutIcon(), ImageCmp.ZOOM_OUT, application.getMessages().zoomOut());
				
		initWidget(panel);
	}
	
	private PushButton createZoomButton(DockPanel panel, ImageResource imgRes, int mode, String title){
		PushButton btn  = new PushButton(new Image(imgRes));
		panel.add(btn, DockPanel.EAST);
		btn.setStylePrimaryName("btn-imageNavigation");
		btn.setTitle(title);
		panel.setCellWidth(btn, "50px");
		zoomModes.put(btn, mode);
		btn.addClickHandler(this);
		return btn;
	}

	public void onClick(ClickEvent evt) {
		Object sender = evt.getSource();
		if(sender.equals(btnZoom100) ||
				sender.equals(btnZoomHeight) ||
				sender.equals(btnZoomIn) ||
				sender.equals(btnZoomOut) ||
				sender.equals(btnZoomPage) ||
				sender.equals(btnZoomWidth)){
			imageCmp.zoomImage(zoomModes.get(sender));
		}
	}

	public void setImageCmp(ImageCmp imageCmp) {
		this.imageCmp = imageCmp;
	}
	
	public void updateUI(){
		if(application.getCurrentItem()==null){
			panel.setVisible(false);
		}
		else{
			panel.setVisible(true);
		}
	}
}
